package com.meng.thrift.client.a_controller;

import com.meng.thrift.client.b_service.TestService;
import com.meng.thrift.client.thrift.entity.User;
import com.meng.thrift.client.thrift.util.GetThriftServerObj;
import com.meng.thrift.client.thrift.util.ThriftIpPortEnum;
import com.meng.thrift.client.thrift.inter.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 测试控制层
 *
 * @author MENG
 * @version 2017/10/27
 * @see
 */
@Controller
@RequestMapping("test")
public class TestController
{

    @GetThriftServerObj(ipPort = ThriftIpPortEnum.MENGLOCAL_IP_PORT_8191)
    private UserService.Client userService;

    @Autowired
    private TestService testService;

    @RequestMapping("tind")
    public ModelAndView toIndex()
    {
        Map<String,Object> map = new HashMap<>();
        try
        {
            testService.test();

            List<User> userList = userService.getUser(null);

            System.out.println("-------------------------------------------------");

            System.out.println("Thrift同步调用"+userList);

            if(userList.size() > 0)
            {
                User user = (User)userList.get(0);

                map.put("user",user);
            }
            else
            {
                map.put("user","没有数据！");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

        return new ModelAndView("index",map);
    }
}
